home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Standard Catalog Package / DTS AddressOMatic / Src / PositionDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-05  |  1.7 KB  |  64 lines  |  [TEXT/KAHL]

  1. /*                                PositionDialog.c                                */
  2. /*
  3.  * DTS AddressOMatic Sample
  4.  * PositionDialog.c
  5.  * Copyright © 1993 Apple Computer Inc. All rights reserved.
  6.  *
  7.  * PositionDialog relocates a dialog or alert so it is centered on the main screen,
  8.  * 1/3 down from the top. This is a utility routine that is generally independent
  9.  * of the AddressOMatic. It is not quite correct as it doesn't compensate for
  10.  * multiple screens.
  11.  */
  12. #include "AddressOMaticTest.h"
  13.  
  14. /*
  15.  * No side-effects allowed
  16.  */
  17. #define Max(a, b) (((a) > (b)) ? (a) : (b))
  18.  
  19. /*
  20.  * PositionDialog
  21.  * Position a dialog given its resource type and id.
  22.  */
  23. void
  24. PositionDialog(
  25.         ResType            dialogType,
  26.         short            dialogID
  27.     )
  28. {
  29.         Handle            template;
  30.         
  31.         template = GetResource(dialogType, dialogID);
  32.         if (template != NULL)
  33.             PositionRect((Rect *) (*template));
  34. }
  35.  
  36. /*
  37.  * PositionRect
  38.  * Given a rectangle, reposition it so it is centered on the main screen, and
  39.  * located at the top 1/3 of the screen. This version assumes that all dialogs
  40.  * (or whatever) will actually fit on the screen. It also does not look at
  41.  * the display that the FrontWindow is located on, but assumes that it will
  42.  * always draw on the main screen.
  43.  */
  44. void
  45. PositionRect(
  46.         Rect            *boundsPtr
  47.     )
  48. {
  49.         short            leftEdge;
  50.         short            topEdge;
  51.         short            screenWidth;
  52.         short            screenHeight;
  53.  
  54.         screenWidth = width(qd.screenBits.bounds);
  55.         screenHeight = height(qd.screenBits.bounds);
  56.         leftEdge = Max((screenWidth - width(*boundsPtr)) / 2, 0);
  57.         topEdge = (screenHeight - height(*boundsPtr)) / 3;
  58.         topEdge = Max(topEdge, GetMBarHeight() + 1);
  59.         boundsPtr->right = width(*boundsPtr) + leftEdge;
  60.         boundsPtr->left = leftEdge;
  61.         boundsPtr->bottom = height(*boundsPtr) + topEdge;
  62.         boundsPtr->top = topEdge;
  63. }
  64.